//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "FuturesConvAdjustmentQuote.h"
using namespace Cephei::QL::Quotes;
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Quote.h>
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (Cephei::QL::Indexes::IIborIndex^ index, String^ immCode, Cephei::QL::IQuote^ futuresQuote, Cephei::QL::IQuote^ volatility, Cephei::QL::IQuote^ meanReversion) : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
    CIborIndex^ _Cindex;
    CQuote^ _CfuturesQuote;
    CQuote^ _Cvolatility;
    CQuote^ _CmeanReversion;
    try
    {
#ifdef HANDLE
        _phFuturesConvAdjustmentQuote = NULL;
#endif
        _Cindex = safe_cast<CIborIndex^> (index);
        _Cindex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _index = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_Cindex->GetShared ()); 
        std::string _immCode = (std::string)ValueHelper::Convert (immCode);
        _CfuturesQuote = safe_cast<CQuote^> (futuresQuote);
        _CfuturesQuote->Lock();
        Handle<QuantLib::Quote>& _futuresQuote = static_cast<Handle<QuantLib::Quote>&> (_CfuturesQuote->GetHandle ()); 
        _Cvolatility = safe_cast<CQuote^> (volatility);
        _Cvolatility->Lock();
        Handle<QuantLib::Quote>& _volatility = static_cast<Handle<QuantLib::Quote>&> (_Cvolatility->GetHandle ()); 
        _CmeanReversion = safe_cast<CQuote^> (meanReversion);
        _CmeanReversion->Lock();
        Handle<QuantLib::Quote>& _meanReversion = static_cast<Handle<QuantLib::Quote>&> (_CmeanReversion->GetHandle ()); 
        _ppFuturesConvAdjustmentQuote = new boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote> (new QuantLib::FuturesConvAdjustmentQuote ( _index,  _immCode,  _futuresQuote,  _volatility,  _meanReversion ));
        SetQuote (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppFuturesConvAdjustmentQuote));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cindex != nullptr) _Cindex->Unlock();
        if (_CfuturesQuote != nullptr) _CfuturesQuote->Unlock();
        if (_Cvolatility != nullptr) _Cvolatility->Unlock();
        if (_CmeanReversion != nullptr) _CmeanReversion->Unlock();
    }
}
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (Cephei::QL::Indexes::IIborIndex^ index, DateTime futuresDate, Cephei::QL::IQuote^ futuresQuote, Cephei::QL::IQuote^ volatility, Cephei::QL::IQuote^ meanReversion) : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
    CIborIndex^ _Cindex;
    CQuote^ _CfuturesQuote;
    CQuote^ _Cvolatility;
    CQuote^ _CmeanReversion;
    try
    {
#ifdef HANDLE
        _phFuturesConvAdjustmentQuote = NULL;
#endif
        _Cindex = safe_cast<CIborIndex^> (index);
        _Cindex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _index = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_Cindex->GetShared ()); 
        QuantLib::Date _futuresDate = (QuantLib::Date)ValueHelper::Convert (futuresDate);
        _CfuturesQuote = safe_cast<CQuote^> (futuresQuote);
        _CfuturesQuote->Lock();
        Handle<QuantLib::Quote>& _futuresQuote = static_cast<Handle<QuantLib::Quote>&> (_CfuturesQuote->GetHandle ()); 
        _Cvolatility = safe_cast<CQuote^> (volatility);
        _Cvolatility->Lock();
        Handle<QuantLib::Quote>& _volatility = static_cast<Handle<QuantLib::Quote>&> (_Cvolatility->GetHandle ()); 
        _CmeanReversion = safe_cast<CQuote^> (meanReversion);
        _CmeanReversion->Lock();
        Handle<QuantLib::Quote>& _meanReversion = static_cast<Handle<QuantLib::Quote>&> (_CmeanReversion->GetHandle ()); 
        _ppFuturesConvAdjustmentQuote = new boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote> (new QuantLib::FuturesConvAdjustmentQuote ( _index,  _futuresDate,  _futuresQuote,  _volatility,  _meanReversion ));
        SetQuote (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppFuturesConvAdjustmentQuote));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cindex != nullptr) _Cindex->Unlock();
        if (_CfuturesQuote != nullptr) _CfuturesQuote->Unlock();
        if (_Cvolatility != nullptr) _Cvolatility->Unlock();
        if (_CmeanReversion != nullptr) _CmeanReversion->Unlock();
    }
}
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote>& childNative, Object^ owner) : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
#ifdef HANDLE
	_phFuturesConvAdjustmentQuote = NULL;
#endif
	_ppFuturesConvAdjustmentQuote = &childNative;
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppFuturesConvAdjustmentQuote));
}
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (QuantLib::FuturesConvAdjustmentQuote& childNative, Object^ owner) : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
#ifdef HANDLE
	_phFuturesConvAdjustmentQuote = NULL;
#endif
	_ppFuturesConvAdjustmentQuote = new boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote> (&childNative);
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppFuturesConvAdjustmentQuote));
    _FuturesConvAdjustmentQuoteOwner = owner;
    _QuoteOwner = owner;
}

Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (CFuturesConvAdjustmentQuote^ copy) : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
#ifdef HANDLE
	_phFuturesConvAdjustmentQuote = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFuturesConvAdjustmentQuote = new boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote> (copy->GetShared());
        _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppFuturesConvAdjustmentQuote));
    }
}
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (System::Type^ t) : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
#ifdef HANDLE
	_phFuturesConvAdjustmentQuote = NULL;
#endif
	if (!t->IsSubclassOf(CFuturesConvAdjustmentQuote::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (QuantLib::Handle<QuantLib::FuturesConvAdjustmentQuote>& childNative, Object^ owner)  : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
	_phFuturesConvAdjustmentQuote = &childNative;
	_ppFuturesConvAdjustmentQuote = &static_cast<boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote>>(childNative.currentLink());
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppFuturesConvAdjustmentQuote));
    _FuturesConvAdjustmentQuoteOwner = owner;
}
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (QuantLib::Handle<QuantLib::FuturesConvAdjustmentQuote> childNative)  : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
	_phFuturesConvAdjustmentQuote = &childNative;
	_ppFuturesConvAdjustmentQuote = &static_cast<boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote>>(childNative.currentLink());
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppFuturesConvAdjustmentQuote));
}
#endif
#ifdef STRUCT
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::CFuturesConvAdjustmentQuote (QuantLib::FuturesConvAdjustmentQuote childNative)  : CQuote(CFuturesConvAdjustmentQuote::typeid)
{
#ifdef HANDLE
	_phFuturesConvAdjustmentQuote = NULL;
#endif
	_ppFuturesConvAdjustmentQuote = new boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote> (new QuantLib::FuturesConvAdjustmentQuote (childNative));
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppFuturesConvAdjustmentQuote));
}
#endif

Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::~CFuturesConvAdjustmentQuote ()
{
    if (_ppFuturesConvAdjustmentQuote != NULL)
    {
	    delete _ppFuturesConvAdjustmentQuote;
        _ppFuturesConvAdjustmentQuote = NULL;
    }
}
Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::!CFuturesConvAdjustmentQuote ()
{
    if (_ppFuturesConvAdjustmentQuote != NULL)
    {
	    delete _ppFuturesConvAdjustmentQuote;
    }
}
QuantLib::FuturesConvAdjustmentQuote& Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::GetReference ()
{
    if (_ppFuturesConvAdjustmentQuote == NULL) throw gcnew NativeNullException ();
	return **_ppFuturesConvAdjustmentQuote;
}
boost::shared_ptr<QuantLib::FuturesConvAdjustmentQuote>& Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::GetShared ()
{
    if (_ppFuturesConvAdjustmentQuote == NULL) throw gcnew NativeNullException ();
	return *_ppFuturesConvAdjustmentQuote;
}
QuantLib::FuturesConvAdjustmentQuote* Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::GetPointer ()
{
    if (_ppFuturesConvAdjustmentQuote == NULL) throw gcnew NativeNullException ();
	return &**_ppFuturesConvAdjustmentQuote;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FuturesConvAdjustmentQuote>& Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::GetHandle ()
{
	if (_phFuturesConvAdjustmentQuote == NULL)
	{
		_phFuturesConvAdjustmentQuote = new Handle<QuantLib::FuturesConvAdjustmentQuote> (*_ppFuturesConvAdjustmentQuote);
	}
	return *_phFuturesConvAdjustmentQuote;
}
#endif
bool Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::HasNative () 
{
	return (_ppFuturesConvAdjustmentQuote != NULL);
}

Double Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::FuturesValue::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFuturesConvAdjustmentQuote)->futuresValue ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::ImmDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppFuturesConvAdjustmentQuote)->immDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::IsValid::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppFuturesConvAdjustmentQuote)->isValid ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::MeanReversion::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFuturesConvAdjustmentQuote)->meanReversion ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Quotes::IFuturesConvAdjustmentQuote^ Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppFuturesConvAdjustmentQuote)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::Value::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFuturesConvAdjustmentQuote)->value ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Quotes::CFuturesConvAdjustmentQuote::Volatility::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFuturesConvAdjustmentQuote)->volatility ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Quotes::IFuturesConvAdjustmentQuote^ Cephei::QL::Quotes::CFuturesConvAdjustmentQuote_Factory::Create (Cephei::QL::Indexes::IIborIndex^ index, String^ immCode, Cephei::QL::IQuote^ futuresQuote, Cephei::QL::IQuote^ volatility, Cephei::QL::IQuote^ meanReversion)
{
    return gcnew CFuturesConvAdjustmentQuote ( index,  immCode,  futuresQuote,  volatility,  meanReversion);
}
Cephei::QL::Quotes::IFuturesConvAdjustmentQuote^ Cephei::QL::Quotes::CFuturesConvAdjustmentQuote_Factory::Create (Cephei::QL::Indexes::IIborIndex^ index, DateTime futuresDate, Cephei::QL::IQuote^ futuresQuote, Cephei::QL::IQuote^ volatility, Cephei::QL::IQuote^ meanReversion)
{
    return gcnew CFuturesConvAdjustmentQuote ( index,  futuresDate,  futuresQuote,  volatility,  meanReversion);
}
